﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Nop.Core.Domain.Shipping
{
    public class ShippingTimeWindowEx
    {
        public int Id { get; set; }
        /// <summary>
        /// The description of the current time window
        /// </summary>
        public virtual string Description { get; set; }
        /// <summary>
        /// The time window begins in 24-hour format. 13 stands for 1 PM
        /// </summary>
        public virtual int NoEarlyThan { get; set; }
        /// <summary>
        /// The time window ends in 24-hour format. 13 stands for 1 PM
        /// </summary>
        public virtual int NoLateThan { get; set; }

        /// <summary>
        /// allow ordertype like 1,2
        /// </summary>
        public virtual IList<int> AllowOrderType { get; set; }
        /// <summary>
        /// allow AddressType like 1,2
        /// </summary>
        public virtual IList<int> AllowAddressType { get; set; }

        /// <summary>
        /// The cutoff time in minutes of day in order for this time window to be selectable same day
        /// </summary>
        public virtual int SameDayCutoff { get; set; }

        /// <summary>
        /// The display order
        /// </summary>
        public int DisplayOrder { get; set; }


        public ShippingTimeWindowEx(ShippingTimeWindow model)
        {
            this.Id = model.Id;
            this.Description = model.Description;
            this.DisplayOrder = model.DisplayOrder;
            this.NoEarlyThan = model.NoEarlyThan;
            this.NoLateThan = model.NoLateThan;
            this.SameDayCutoff = model.SameDayCutoff;
            this.AllowOrderType = !string.IsNullOrEmpty(model.AllowAddressType) ? model.AllowOrderType.Split(',').Select(y => Convert.ToInt32(y)).ToList() : new List<int>();
            this.AllowAddressType = !string.IsNullOrEmpty(model.AllowAddressType) ? model.AllowAddressType.Split(',').Select(y => Convert.ToInt32(y)).ToList() : new List<int>();
        }
        public static IList<ShippingTimeWindowEx> ConvertShippingTimeWindowEx(IList<ShippingTimeWindow> models)
        {
            return models.Select(x => new ShippingTimeWindowEx(x)).ToList();
        }
    }
}
